package com.project.controller.custom;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.project.bean.OrderBean;
import com.project.bean.UserBean;
import com.project.service.IOrderService;
import org.apache.ibatis.annotations.ResultMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("custom/order")
public class OrderController {
    @Autowired
    private IOrderService service;

    @RequestMapping("addOrder")
    public String addOrder(OrderBean order, HttpServletRequest request){
        //得到登录信息
        UserBean userBean = (UserBean) request.getSession().getAttribute("loginUser");
        //添加订单
        service.add(order,userBean.getId());
        return "ok";
    }

    @RequestMapping("findByOrderUser")
    public IPage<OrderBean> findByOrderUser(Integer pageNO,HttpServletRequest request){
        UserBean loginUser = (UserBean) request.getSession().getAttribute("loginUser");
        System.out.println(pageNO);
        System.out.println(loginUser.getId());
        return service.findByUser(pageNO,loginUser.getId());
    }

    @RequestMapping("findById")
    public OrderBean findById(Integer orderId){
        return service.findById(orderId);
    }
}
